package com.spider.silence.job;

import com.spider.silence.downloader.KaiDiDownLoader;
import com.spider.silence.pool.KaiDiDownLoaderPool;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @description 描述
 * @time 2017/1/16 0016
 */
public class KaiDiJob implements StatefulJob {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        KaiDiDownLoaderPool downLoaderPool = null;
        KaiDiDownLoader downLoader = null;
        try{
            downLoaderPool = KaiDiDownLoaderPool.getInstance();
            downLoader = downLoaderPool.fetchDownLoader(1000);
            List<String> urlList = downLoader.getUrl();
            //生成任务队列
            downLoader.generateTask(urlList);

        }catch(Exception e){
            e.printStackTrace();
        }finally {
            if(downLoader != null){
                downLoaderPool.releaseDownLoader(downLoader);
            }
        }
    }
}
